package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.service.ICertificateTemplateService;
import com.ruoyi.training.vo.certificate.CertificateTemplateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.CertificateTemplate;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 证书模板Controller
 * 
 * @author hcc
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/certificateTemplate")
public class CertificateTemplateController extends BaseController
{
    @Autowired
    private ICertificateTemplateService certificateTemplateService;

    /**
     * 查询证书模板列表
     */
    @RequiresPermissions("training:certificateTemplate:list")
    @GetMapping("/list")
    public TableDataInfo list(CertificateTemplate certificateTemplate)
    {
        startPage();
        List<CertificateTemplate> list = certificateTemplateService.selectCertificateTemplateList(certificateTemplate);
        return getDataTable(list);
    }

    /**
     * 导出证书模板列表
     */
    @RequiresPermissions("training:certificateTemplate:export")
    @Log(title = "证书模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CertificateTemplate certificateTemplate)
    {
        List<CertificateTemplate> list = certificateTemplateService.selectCertificateTemplateList(certificateTemplate);
        ExcelUtil<CertificateTemplate> util = new ExcelUtil<CertificateTemplate>(CertificateTemplate.class);
        util.exportExcel(response, list, "证书模板数据");
    }

    /**
     * 获取证书模板详细信息
     */
    @RequiresPermissions("training:certificateTemplate:query")
    @GetMapping(value = "/{certificateTemplateId}")
    public AjaxResult getInfo(@PathVariable("certificateTemplateId") String certificateTemplateId)
    {
        return success(certificateTemplateService.selectCertificateTemplateByCertificateTemplateId(certificateTemplateId));
    }

    /**
     * 新增证书模板
     */
    @RequiresPermissions("training:certificateTemplate:add")
    @Log(title = "证书模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CertificateTemplate certificateTemplate)
    {
        return toAjax(certificateTemplateService.insertCertificateTemplate(certificateTemplate));
    }

    /**
     * 修改证书模板
     */
    @RequiresPermissions("training:certificateTemplate:edit")
    @Log(title = "证书模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CertificateTemplate certificateTemplate)
    {
        return toAjax(certificateTemplateService.updateCertificateTemplate(certificateTemplate));
    }

    /**
     * 删除证书模板
     */
    @RequiresPermissions("training:certificateTemplate:remove")
    @Log(title = "证书模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certificateTemplateIds}")
    public AjaxResult remove(@PathVariable String[] certificateTemplateIds)
    {
        return toAjax(certificateTemplateService.deleteCertificateTemplateByCertificateTemplateIds(certificateTemplateIds));
    }


    /**
     * 新增证书模板
     */
    @RequiresPermissions("training:certificateTemplate:add")
    @Log(title = "证书模板", businessType = BusinessType.INSERT)
    @PostMapping("/addCertificateTemplate")
    public AjaxResult addCertificateTemplate(@RequestBody CertificateTemplateVo certificateTemplateVo)
    {
        return toAjax(certificateTemplateService.addCertificateTemplate(certificateTemplateVo));
    }

    /**
     * 修改证书模板
     */
    @RequiresPermissions("training:certificateTemplate:edit")
    @Log(title = "证书模板", businessType = BusinessType.UPDATE)
    @PutMapping("/editCertificateTemplate")
    public AjaxResult editCertificateTemplate(@RequestBody CertificateTemplateVo certificateTemplateVo)
    {
        return toAjax(certificateTemplateService.editCertificateTemplate(certificateTemplateVo));
    }

    /**
     * 获取证书模板详细信息
     */
    @RequiresPermissions("training:certificateTemplate:query")
    @GetMapping(value = "/getCertificateTemplateInfo/{certificateTemplateId}")
    public AjaxResult getCertificateTemplateInfo(@PathVariable("certificateTemplateId") String certificateTemplateId)
    {
        return success(certificateTemplateService.getCertificateTemplateInfo(certificateTemplateId));
    }

    /**
     * 复制证书模板
     */
    @RequiresPermissions("training:certificateTemplate:add")
    @GetMapping(value = "/copyCertificateTemplate/{certificateTemplateId}")
    public AjaxResult copyCertificateTemplate(@PathVariable("certificateTemplateId") String certificateTemplateId)
    {
        return success(certificateTemplateService.copyCertificateTemplate(certificateTemplateId));
    }
}
